package com.edu.app.mapper.core;

import com.edu.app.bean.core.SysContract;
import com.edu.app.model.customer.ContractModel;
import com.edu.app.util.AppBaseMapper;

import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SysContractMapper extends AppBaseMapper<SysContract> {
    @Select("SELECT * FROM S_CONTRACT WHERE customer_id = #{id}")
    List<SysContract> GetContractByCustomerId(Integer id);

    @Select("DELETE FROM S_CONTRACT WHERE customer_id = #{id}")
    Integer deleteContractByCustomerId(Integer id);

    @Select("select t1.id,t1.start_date,t1.end_date,t1.amount,t1.points,t1.description,t1.img_copy_url," +
            "t2.id as customer_id,t2.name as customer,t4.id as lesson_id,t4.value as lesson,t3.id as user_id,t3.nickname as user from s_contract t1 " +
            "inner join s_customer t2 on t1.customer_id = t2.id " +
            "inner join s_user t3 on t1.user_id = t3.id " +
            "inner join s_list_of_value t4 on t1.lesson_id = t4.id " +
            "where t2.id = #{id}")
    List<ContractModel> getContractModelByCusId(Integer id);

    @Select("select t1.id,t1.start_date,t1.end_date,t1.amount,t1.points,t1.description,t1.img_copy_url," +
            "t2.id as customer_id,t2.name as customer,t4.id as lesson_id,t4.value as lesson,t3.id as user_id,t3.nickname as user from s_contract t1 " +
            "inner join s_customer t2 on t1.customer_id = t2.id " +
            "inner join s_user t3 on t1.user_id = t3.id " +
            "inner join s_list_of_value t4 on t1.lesson_id = t4.id " +
            "where t1.id = #{id}")
    ContractModel getContractModelByModelId(Integer id);
}